package com.jasonchoi.gateway;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * @Author: JasonChoi
 * @Date: 2019/12/17 11:56
 */
@Configuration
public class RateLimiterConfig{

    /**
     * 方法名称对应配置key-resolver
     * @return
     */
    @Bean
    KeyResolver userKeyResolver() {
        return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("rateLimitParam"));
    }
//    @Bean
//    public KeyResolver ipKeyResolver(){
//        System.out.println("##############ipKeyResolver########################");
//        return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
//    }
}
